package com.med.service;


import com.med.entity.MedicalRecordDO;
import com.med.entity.UserDO;
import com.med.mapper.UserMapper;
import com.med.service.IUserService;
import com.med.vo.UserVO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @BelongsProject: internet-based-healthcare01
 * @BelongsPackage: com.med.service.impl
 * @Author: WWJ
 * @CreateTime: 2025-08-13 16:46
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class UserService implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserDO> queryUserList(UserVO userVO) {
        return userMapper.queryUserList(userVO);
    }

    @Override
    public R<Integer> deleteUser(Integer userId) {
        Integer i = userMapper.deleteUser(userId);
        return R.ok(i);
    }

    @Override
    @Transactional //添加事务保证原子性
    public R<Integer> resetPassword(Integer userId) {
        String password = SecurityUtils.encryptPassword("123456");
        Integer i = userMapper.resetPassword(userId, password);
        return R.ok(i);
    }

    @Override
    public R<Integer> updateStatus(Integer userId) {
        Integer i = userMapper.updateStatus(userId);
        return R.ok(i);
    }

    @Override
    public List<MedicalRecordDO> queryMedicalRecordList(Integer userId) {
        return userMapper.queryMedicalRecordList(userId);
    }
}
